package org.dromara.system.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class UserAgentUtils {


    public static String getUserAgent() {
        Random random = new Random();

        Map<String, String[]> osList = new HashMap<>();
        osList.put("Windows NT", new String[]{"10.0", "6.1", "5.1"});  // Windows 10, 7, XP
        osList.put("Macintosh", new String[]{"14.0", "13.0", "12.0"});  // 最新的 macOS版本
        osList.put("Linux", new String[]{"Ubuntu 22.04", "Ubuntu 20.04", "Debian 11"});  // 最新的 Linux版本
        osList.put("Android", new String[]{"13", "12", "11"});  // 最新的 Android版本
        osList.put("iPhone", new String[]{"15.0", "14.7", "14.6"});  // 最新的 iOS版本

        String osType = (String) osList.keySet().toArray()[random.nextInt(osList.size())];
        String osVersion = osList.get(osType)[random.nextInt(osList.get(osType).length)];
        String osFull = osType + " " + osVersion;

        Map<String, String[]> versions = new HashMap<>();
        versions.put("Chrome", new String[]{"115.0.0.0", "114.0.0.0", "113.0.0.0"});
        versions.put("Firefox", new String[]{"105.0", "104.0", "103.0"});
        versions.put("Safari", new String[]{"16.5", "16.4", "16.3"});
        versions.put("Edge", new String[]{"115.0.1901.183", "114.0.1823.67", "113.0.1774.52"});

        String browser = (String) versions.keySet().toArray()[random.nextInt(versions.size())];
        String browserVersion = versions.get(browser)[random.nextInt(versions.get(browser).length)];
        String browserFull = browser + "/" + browserVersion;

        return "Mozilla/5.0 (" + osFull + ") AppleWebKit/537.36 (KHTML, like Gecko) " + browserFull + " Safari/537.36";
    }
}
